package com.e.dianshang.controller.Api;

import com.e.dianshang.pojo.Goods;
import com.e.dianshang.service.MyeyeService;
import com.e.dianshang.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@Api(value = "用户关注模块",tags = "用户关注api")
public class MyeyeApi {

    @Resource(name = "myeyeService")
    MyeyeService myeyeService;

    JsonResult jsonResult;

    @RequestMapping("selecteMyeye")
    @ApiOperation(value = "用户的收藏记录",httpMethod = "POST")
    @ApiImplicitParam(name = "openid",value = "用户电话或者用户id",dataType = "string")
    public Map selectMyeyeByOpenid(@RequestBody Map map){
        jsonResult=new JsonResult();
        List<Map> map1 = myeyeService.selectMyeyeByOpenid(map);
        if (map1.isEmpty()){
            jsonResult.setMsg("没有任何收藏");
        }else {
            jsonResult.setData(map1);
        }
        return jsonResult.getValues();
    }

    @RequestMapping("insertMyeye")
        @ApiOperation(value = "用户添加收藏记录",httpMethod = "POST")
    @ApiImplicitParam(name = "map",value = "收藏表的相关字段")
    public Map insertMyEye(@RequestBody Map map){
        jsonResult=new JsonResult();
        Integer integer = myeyeService.insertMyEye(map);
        if (integer>0){
            jsonResult.setCode("1");
        }else {
            jsonResult.setCode("0");
        }
        return jsonResult.getValues();
    }

    @RequestMapping("deleteMyeye")
    @ApiOperation(value = "用户删除收藏记录",httpMethod = "GET")
    @ApiImplicitParam(name = "openid",value = "用户电话或者用户id",dataType = "string")
    public Map deleteMyeye(@RequestBody Map map){
        jsonResult=new JsonResult();
        Integer integer = myeyeService.deleteMyeye(map);
        if (integer>0){
            jsonResult.setCode("1");
        }else {
            jsonResult.setCode("0");
        }
        return jsonResult.getValues();
    }
}